#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 1e5+10;
const db Pi = acos(-1.0);

struct Comp{
	db x,y;
	Comp(db _x=0.0,db _y=0.0):x(_x),y(_y){}
	friend Comp operator + (Comp a,Comp b){return Comp(a.x+b.x,a.y+b.y);}
	friend Comp operator - (Comp a,Comp b){return Comp(a.x-b.x,a.y-b.y);}
	friend Comp operator * (Comp a,Comp b){return Comp(a.x * b.x - a.y * b.y,a.x * b.y + a.y * b.x);}
}F[N<<2],G[N<<2],Wn[32];
int lg[N<<2],rev[N<<2],len,n,m,a1,a2,b1,b2,a[N],b[N],A[N<<2];
ll ans;

void FFT(Comp *f,int on = 1){
	for(int i = 1;i < len;i++) if(i < rev[i]) swap(f[i],f[rev[i]]);
	for(int h = 2;h <= len;h <<= 1){
		Comp wn = Wn[lg[h]]; if(on == -1) wn.y = -wn.y;
		for(int i = 0;i < len;i += h){
			Comp w = Comp(1,0);
			for(int k = i;k < i + h / 2;k++){
				Comp u = f[k],v = f[k+h/2]*w; w = w * wn;
				f[k] = u + v; f[k+h/2] = u - v;
			}
		}
	}if(on == -1) for(int i = 0;i < len;i++) f[i].x /= len;
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,m = in;
	for(int i = 1;i <= n;i++) a[i] = in,a1 += a[i] * a[i],a2 += a[i];
	for(int i = 1;i <= n;i++) b[i] = in,b1 += b[i] * b[i],b2 += b[i];
	for(int i = 1;i <= n;i++){
		F[i] = F[i+n] = Comp(a[n-i+1],0);
		G[i] = Comp(b[i],0);
	}
	len = 1; for(;len<3*n;len<<=1);
	for(int i = 1;i < len;i++) rev[i] = rev[i>>1]>>1 | (i & 1 ? len >> 1 : 0);
	for(int h = 1;h <= len;h<<=1) lg[h] = lg[h>>1] + 1,Wn[lg[h]] = Comp(cos(Pi*2/h),sin(Pi*2/h));
	FFT(F); FFT(G); for(int i = 0;i < len;i++) F[i] = F[i] * G[i];
	FFT(F,-1); for(int i = 0;i < len;i++) A[i] = F[i].x + 0.5;
	ans = 0x3f3f3f3f3f3f3f3f;
	for(int i = 1;i <= n;i++)
		for(int j = -m;j <= m;j++)
			ans = min(ans,a1 + b1 + n * j * j + 2ll * j * (a2 - b2) - 2 * A[i+n]);
	printf("%lld\n",ans);
	return 0;
}

